extends StateBase

@onready var bornTimer:Timer = $BornTimer

@export var bornInterval = 0.5
@export var maxCount = 10

var bornCount = 0
var ownerNode:Boss01

func enter(obj):
	ownerNode = obj
	bornCount = 0
	
	bornTimer.wait_time = bornInterval
	bornTimer.timeout.connect(bornBullet)
	bornTimer.start()
	
	

func exit(obj):
	bornTimer.stop()
	bornTimer.timeout.disconnect(bornBullet)


func run(delta, obj):
	pass
	

func bornBullet():
	var inst:BulletAutoTrace = Global.createSceneInst("BulletAutoTrace")
	get_tree().current_scene.add_child(inst)
	if get_tree().get_nodes_in_group("Player").size() > 0:
		inst.setTarget(get_tree().get_nodes_in_group("Player")[0])
	inst.global_position = ownerNode.global_position
	
	bornCount += 1
	if bornCount >= maxCount:
		ownerNode.stateMachine.removeState(name, ownerNode)
		
	
